#!/bin/csh 
#.......................................................................
#
# Merge files with dates : 20071231 20080101 ... 20081231 20090101 
#
# Remapping to 2x2.5 grid 
#
# Author : Kai Zhang 
#.......................................................................

setenv work /pic/scratch/zhan524/fire/work
setenv data /pic/scratch/zhan524/fire/data
setenv src  /pic/scratch/zhan524/fire/fire

cd $work
cp -f ${src}/*.ncl $work

##########################################################################
##### Daily emission for BC, OC, and SO2 
##########################################################################
###foreach yy (2003 2004 2005 2006 2007 2008 2009 2010 2011 )
###foreach tp (BC OC SO2) 
###
###cat > loadit_${tp}_${yy} << EOF
###tp = "${tp}" 
###yy = "${yy}" 
###EOF
###
###cat ${src}/create_emission_cam5_head.ncl loadit_${tp}_${yy} ${src}/create_emission_cam5_base.ncl > tmp_${tp}_${yy}.ncl 
###ncl tmp_${tp}_${yy}.ncl >& err_ncl_${tp}_${yy} & 
###
###end # tp 
###end # yy
###
###
###wait 
###
##########################################################################
##### Creat tmp files containing monthly average emissions  
##########################################################################
###foreach yy (2003 2004 2005 2006 2007 2008 2009 2010 2011 )
###foreach tp (BC OC SO2)
###
###cat > loadit_${tp}_${yy} << EOF
###tp = "${tp}" 
###yy = "${yy}" 
###EOF
###
###cdo monavg emis_GFED3.1_daily_${tp}_${yy}_2x2.5.nc tmp_GFED3.1_monthly_${tp}_${yy}_2x2.5.nc >& null & 
###
###end # tp 
###end # yy
###
###wait
###
###
##########################################################################
##### daily average emission files  
##########################################################################
###foreach yy (2003 2004 2005 2006 2007 2008 2009 2010 2011 )
###
###cat > loadit_dm_${yy} << EOF
###yy = "${yy}" 
###EOF
###
###cat loadit_dm_${yy} ${src}/create_emission_cam5_num_a1.ncl > tmp_num_a1_${yy}.ncl 
###ncl tmp_num_a1_${yy}.ncl >& err_ncl_num_a1_${yy} & 
###
###cat loadit_dm_${yy} ${src}/create_emission_cam5_num_a2.ncl > tmp_num_a2_${yy}.ncl 
###ncl tmp_num_a2_${yy}.ncl >& err_ncl_num_a2_${yy} & 
###
###cat loadit_dm_${yy} ${src}/create_emission_cam5_so4_a1.ncl > tmp_so4_a1_${yy}.ncl 
###ncl tmp_so4_a1_${yy}.ncl >& err_ncl_so4_a1_${yy} & 
###
###cat loadit_dm_${yy} ${src}/create_emission_cam5_so4_a2.ncl > tmp_so4_a2_${yy}.ncl 
###ncl tmp_so4_a2_${yy}.ncl >& err_ncl_so4_a2_${yy} & 
###
###cat loadit_dm_${yy} ${src}/create_emission_cam5_so2.ncl > tmp_so2_${yy}.ncl 
###ncl tmp_so2_${yy}.ncl >& err_ncl_so2_${yy} & 
###
###end # yy 


##
## monthly average emission files  
##
foreach yy (2003 2004 2005 2006 2007 2008 2009 2010 2011 )

cat > loadit_mm_${yy} << EOF
yy = "${yy}" 
EOF

##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_BC.ncl > tmp_mmbc_${yy}.ncl
##ncl tmp_mmbc_${yy}.ncl >& err_ncl_bc_${yy}  
##
##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_OC.ncl > tmp_mmOC_${yy}.ncl
##ncl tmp_mmOC_${yy}.ncl >& err_ncl_OC_${yy} 
##
##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_so2.ncl > tmp_mmso2_${yy}.ncl
##ncl tmp_mmso2_${yy}.ncl >& err_ncl_so2_${yy} 
##
### need BC and OC files 
##
##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_num_a1.ncl > tmp_mmnum_a1_${yy}.ncl 
##ncl tmp_mmnum_a1_${yy}.ncl >& err_ncl_num_a1_${yy} & 
##
##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_num_a2.ncl > tmp_mmnum_a2_${yy}.ncl 
##ncl tmp_mmnum_a2_${yy}.ncl >& err_ncl_num_a2_${yy} & 

cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_so4_a1_cam5.ncl > tmp_mmso4_a1_cam5_${yy}.ncl 
ncl tmp_mmso4_a1_cam5_${yy}.ncl >& err_ncl_so4_a1_cam5_${yy} & 

cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_so4_a1_gfed.ncl > tmp_mmso4_a1_gfed_${yy}.ncl 
ncl tmp_mmso4_a1_gfed_${yy}.ncl >& err_ncl_so4_a1_gfed_${yy} & 

##cat loadit_mm_${yy} ${src}/create_emission_cam5_monthly_so4_a2.ncl > tmp_mmso4_a2_${yy}.ncl 
##ncl tmp_mmso4_a2_${yy}.ncl >& err_ncl_so4_a2_${yy} & 

end



